﻿//===============================================================================
//	LuaGlueScene.cpp
//	LUA -> C++ 地图相关接口管理器
//===============================================================================


#include "LuaGlueScene.h"

#include "LuaGlue.h"

#include "../share/LuaGlueCommon.h"

#include "LuaManager.h"
#include "../share/user_define.h"

#include "ManagerHelper.h"
#include "Map.h"


#include "PlayerDataStruct.inl"
#include "PlayerTemporaryDataDefinition.h"
#include "MapSlot.h"
#include "scene_logic.h"

//-------------------------------------------------------------------------------
int32_t Bufer_SetSceneTempValue(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 3, "Bufer_SetSceneTempValue");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Bufer_SetSceneTempValue");
	MacroIsNumber(ls, ++_pos, "Bufer_SetSceneTempValue");
	MacroIsNumber(ls, ++_pos, "Bufer_SetSceneTempValue");

	_pos = 0;
	int32_t _sid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _idx = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _value = MacroGetIntegerArgument(ls, ++_pos);

	Map* _map = MapManagerPtr->GetScenePtrBySceneKey(_sid);
	if (_map != nullptr)
	{
		_map->SetTempValue(_idx, _value);
	}
	return 0;

	_safe_guard_end;

	return 0;
}


//-------------------------------------------------------------------------------
int32_t Bufer_GetSceneTempValue(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 2, "Bufer_GetSceneTempValue");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Bufer_GetSceneTempValue");
	MacroIsNumber(ls, ++_pos, "Bufer_GetSceneTempValue");

	_pos = 0;
	int32_t _sid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _idx = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _value = MacroGetIntegerArgument(ls, ++_pos);

	if (!MapManagerPtr)
	{
		return 0;
	}

	Map* _map = MapManagerPtr->GetScenePtrBySceneKey(_sid);
	if (_map != nullptr)
	{
		uint32_t _iVal = _map->GetTempValue(_idx);
		MacroPushInteger(ls, _iVal);
		return 1;
	}

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Map_SetSceneElementViewGroup(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 3, "Map_SetSceneElementViewGroup");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Map_SetSceneElementViewGroup");
	MacroIsNumber(ls, ++_pos, "Map_SetSceneElementViewGroup");
	MacroIsNumber(ls, ++_pos, "Map_SetSceneElementViewGroup");

	_pos = 0;
	int32_t _scene_id = MacroGetIntegerArgument(ls, ++_pos);
	uint32_t _element_id = MacroGetUnsignedIntegerArgument(ls, ++_pos);
	int32_t _view_group_id = MacroGetIntegerArgument(ls, ++_pos);

	Map* _map = MapManagerPtr->GetScenePtrBySceneKey(_scene_id);
	if (_map != nullptr)
	{
		_map->SetElementViewGroup(_element_id, _view_group_id);
	}

	return 0;
	
	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Scene_SetSceneMonsterHp(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 3, "Scene_SetSceneMonsterHp");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Scene_SetSceneMonsterHp");
	MacroIsNumber(ls, ++_pos, "Scene_SetSceneMonsterHp");
	MacroIsNumber(ls, ++_pos, "Scene_SetSceneMonsterHp");

	_pos = 0;
	int32_t _scene_id = MacroGetIntegerArgument(ls, ++_pos);
	uint32_t _element_key = MacroGetUnsignedIntegerArgument(ls, ++_pos);
	int32_t _hp = MacroGetIntegerArgument(ls, ++_pos);


	return 0;

	_safe_guard_end;

	return 0;
}




//-------------------------------------------------------------------------------
int32_t Scene_StartPvPScene(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Scene_SetPvPStart");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Scene_SetPvPStart");

	_pos = 0;

//	MapSlot::GetInstance().startPvPScene(_scene->GetKey());

	return 0;

	_safe_guard_end;

	return 0;
}


//-------------------------------------------------------------------------------
int32_t Scene_SetPvPSceneStart(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Scene_SetPvPSceneStart");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Scene_SetPvPSceneStart");

	_pos = 0;
	uint32_t _sceneKey = MacroGetUnsignedIntegerArgument(ls, ++_pos);

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Scene_PvPCheckIsNextAutoTime(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 2, "Scene_CheckIsNextAutoTime");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Scene_CheckIsNextAutoTime");
	MacroIsNumber(ls, ++_pos, "Scene_CheckIsNextAutoTime");

	_pos = 0;
	uint32_t _sceneKey = MacroGetUnsignedIntegerArgument(ls, ++_pos);
	int32_t _intervalTime = MacroGetIntegerArgument(ls, ++_pos);

	int32_t _is_right_time = 0;// _scene->CheckIsNextAutoTime(_intervalTime);

	MacroPushInteger(ls, _is_right_time);

	return 1;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Scene_PvPCreateMonster(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 2, "Scene_CreateMonster");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Scene_CreateMonster");
	MacroIsNumber(ls, ++_pos, "Scene_CreateMonster");

	_pos = 0;
	uint32_t _sceneKey = MacroGetUnsignedIntegerArgument(ls, ++_pos);
	int32_t _count = MacroGetIntegerArgument(ls, ++_pos);


	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Scene_PvPCheckHasEnoughFreeMonster(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Scene_PvPCheckHasEnoughFreeMonster");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Scene_PvPCheckHasEnoughFreeMonster");

	_pos = 0;
	uint32_t _sceneKey = MacroGetUnsignedIntegerArgument(ls, ++_pos);


	uint32_t _has_enough = 0;// _scene->PvPCheckHasEnoughFreeMonster();

	MacroPushInteger(ls, _has_enough ? _has_enough :0);

	return 1;

	_safe_guard_end;

	return 0;
}


// 玩家是否在线
int32_t Scene_IsPlayerOnline(lua_State* ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Scene_IsPlayerOnline");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Scene_IsPlayerOnline");

	_pos = 0;
	int32_t playerId = MacroGetIntegerArgument(ls, ++_pos);
	Player* player = CSceneLogic::GetInstance().GetPlayerByPlayerID(playerId);
	if ( player == NULL )
	{
		MacroPushInteger(ls, 0);
	}
	else
	{
		MacroPushInteger(ls, 1);
	}

	return 1;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
